package com.xbongbong.pro.onlineEditor.sdk;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.ErrorCode;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;

/**
 * @author: yingjf
 * @date: 2023/3/6 18:31
 * @description: 在线编辑器基础vo  这边不能复用XbbResponse  wps在线编辑器的返回格式固定不能修改
 */
@ToString
@Data
public class OnlineEditorResultVO<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 错误信息返回
     */
    protected String msg;
    /**
     * 错误码
     */
    protected Integer code;
    /**
     * 返回是否成功
     */
    private Boolean success;
    /**
     * 返回值核心内容
     */
    private T data;

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public OnlineEditorResultVO(T t) {
        this.code = 0;
        this.msg = ErrorCodeEnum.API_SUCCESS.getMsg();
        this.success = code.equals(0);
        data = t;
    }

    public OnlineEditorResultVO(Integer code, String message) {
        this.code = code;
        this.msg = message;
        this.setSuccess(code.equals(0));
    }

    public OnlineEditorResultVO(XbbException e) {
        this(e.getCode(), e.getMsg());
    }
    public OnlineEditorResultVO(ErrorCode errorCode, String message) {
        this(errorCode.getCode(), message);
    }
}
